package cc.wanforme.chipmunity.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.wanforme.chipmunity.common.bean.WebResponse;
import cc.wanforme.chipmunity.controller.base.BaseController;
import cc.wanforme.chipmunity.system.po.Message;
import cc.wanforme.chipmunity.system.service.interfaces.MessageService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @author wanne
 * 2019年8月18日
 * 
 */
@Controller
@RequestMapping("/messge")
public class MessageController extends BaseController{
	private static final Logger log = LoggerFactory.getLogger(MessageController.class);
	
	@Autowired
	private MessageService messageService;
	
	
	@RequestMapping("/update")
	@ResponseBody
	@ApiOperation("更新消息")
	@ApiImplicitParam(name="message", dataType="Message", value="消息，不更新senderId、receiverId、com、createTime", required=true)
	@PreAuthorize("hasAuthority('message:update')")
	public WebResponse updateMessage(@RequestBody(required=true) Message message) {
		try {
			return messageService.updateMessage(message);
		} catch (Exception e) {
			log.error("更新消息", e);
			return WebResponse.fail("更新失败！服务器异常！");
		}
	}
	
}
